/**   
* @Title: YwShouLiServiceImpl.java 
* @Package com.zjdiepu.www.biz.zpp 
* 
* @author zhangpp
* @date 2017年5月31日 上午11:35:49 
* @version V1.0   
*/
package com.zjdiepu.www.biz.zpp;
import java.io.FileInputStream;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.type.CodeType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.dao.base.DpBaseDealerInfoMapper;
import com.zjdiepu.www.dao.base.DpBaseDealerInfoSubMapper;
import com.zjdiepu.www.dao.dz.DzLoanMiddleBankImportMapper;
import com.zjdiepu.www.dao.fk.FkAuditListMapper;
import com.zjdiepu.www.dao.yw.YwBusinessCarMapper;
import com.zjdiepu.www.dao.yw.YwBusinessLoanMapper;
import com.zjdiepu.www.dao.yw.YwBusinessMapper;
import com.zjdiepu.www.dao.yw.YwFeesMapper;
import com.zjdiepu.www.dao.yw.YwFeesSubMapper;
import com.zjdiepu.www.dao.yw.YwLoanAbandonMapper;
import com.zjdiepu.www.dao.yw.YwTransferMapper;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.dao.zpp.YwShouLiDao;
import com.zjdiepu.www.ibiz.base.ISerialNumberService;
import com.zjdiepu.www.ibiz.zpp.DaiZhongYwService;
import com.zjdiepu.www.ibiz.zpp.YwShouLiService;
import com.zjdiepu.www.model.base.dto.DpBaseDealerInfo;
import com.zjdiepu.www.model.base.dto.DpBaseDealerInfoSub;
import com.zjdiepu.www.model.dz.dto.DzLoanMiddleBankImport;
import com.zjdiepu.www.model.fk.dto.FkAuditList;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoan;
import com.zjdiepu.www.model.yw.dto.YwFees;
import com.zjdiepu.www.model.yw.dto.YwFeesSub;
import com.zjdiepu.www.model.yw.dto.YwLoanAbandon;
import com.zjdiepu.www.model.yw.dto.YwTransfer;
import com.zjdiepu.www.model.zpp.dzyw.vo.FkAuditListVo;
import com.zjdiepu.www.model.zpp.pub.ext.ParamsExt;
import com.zjdiepu.www.model.zpp.pub.ext.WhereSqlExt;
import com.zjdiepu.www.model.zpp.pub.vo.ParamsVo;
import com.zjdiepu.www.model.zpp.ywsl.dto.DaKuanKeHuTable;
import com.zjdiepu.www.model.zpp.ywsl.ext.DaKuanKeHuTableExe;

/**      
 * 项目名称：diepu-parent-biz   
 * 类名称：YwShouLiServiceImpl   
 * 类描述：   
 * 创建人：zhangpp
 * 创建时间：2017年5月31日 上午11:35:49   
 * 修改人：zhangpp
 * 修改时间：2017年5月31日 上午11:35:49   
 * 修改备注：   
 * @version V1.0     
 */
@Service
public class YwShouLiServiceImpl implements YwShouLiService
{

	@Autowired
	private YwShouLiDao YwShouLiDao;
	
	@Autowired
	private YwFeesMapper ywFeesMapper;
	
	@Autowired
	private YwBusinessMapper ywBusinessMapper;
	
	@Autowired
	private DaiZhongYwService daiZhongYwService;
	
	@Autowired
	private FkAuditListMapper fkAuditListMapper;
	
	@Autowired
	private YwTransferMapper isYwTransferMapper;
	
	@Autowired
	private YwLoanAbandonMapper ywLoanAbandonMapper;
	
	@Autowired
	private YwFeesSubMapper ywFeesSubMapper;
	
	@Autowired
	private YwBusinessCarMapper ywBusinessCarMapper;
	
	@Autowired
	private DpBaseDealerInfoMapper dpBaseDealerInfoMapper;
	
	@Autowired
	private DpBaseDealerInfoSubMapper dpBaseDealerInfoSubMapper;
	
	@Autowired
	private ISerialNumberService serialNumberService;
	
	@Autowired
	private DzLoanMiddleBankImportMapper dzLoanMiddleBankImportMapper;
	
	@Autowired
	private YwBusinessLoanMapper ywBusinessLoanMapper;
	
	@Autowired
	private PublicDao publicDao;
	
	@Autowired
	private YwTransferMapper ywTransferMapper;
	
	
	/* 
	* @author zhangpp
	* <p>Title: getSalesmanCode</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#getSalesmanCode(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public ParamsVo getSalesmanCode(ParamsExt paramsExt) {
		
		return YwShouLiDao.getSalesmanCode(paramsExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: getBaseRemitAccountList</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @return 
	* @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#getBaseRemitAccountList(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt) 
	* @version V1.0
	*/
	@Override
	public List<ParamsVo> getBaseRemitAccountList(ParamsExt paramsExt) {
		
		return YwShouLiDao.getBaseRemitAccountList(paramsExt);
	}

	/* 
	* @author zhangpp
	* <p>Title: ywShouLiAnJieDayBiaoBiao</p> 
	* <p>Description: </p> 
	* @param ywFees
	* @param ywBusiness
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#ywShouLiAnJieDayBiaoBiao(com.zjdiepu.www.model.yw.dto.YwFees, com.zjdiepu.www.model.yw.dto.YwBusiness, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void diepuYwShouLiAnJieDayBiaoBiao(YwFees ywFees, YwBusiness ywBusiness,
			AbstractSysUser currentUser,String key, String value) {
		
		
		if(null == ywBusiness || ("").equals(ywBusiness))
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		
		String userId = currentUser.getId();
		String creatorName = currentUser.getName();
		
		if(null == userId || null == creatorName)
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		
		//业务员编号
		String busiId = ywFees.getBusiId();
		
		//查询业务信息表数据
		YwBusiness business = ywBusinessMapper.selectByPrimaryKey(busiId);
		if(null == business)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		}
		
		//安街日报表的数据
		String fees_id = "";
		
		//查询  如果当前  yw_fees 表数据如果存在 则修改
		YwFees fees = new YwFees();
		fees.setBusiId(busiId);
		fees.setDpStatus(1);
		fees = ywFeesMapper.selectRefined(fees);
		if(null == fees)
		{
			//插入  yw_fees 表数据       
			ywFees.initInsertData(userId, creatorName);
			fees_id = ywFees.getId();
			ywFees.setCusId(business.getCustomerId());
			int insertCount = ywFeesMapper.insert(ywFees);
			if(insertCount < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
			}
		}
		
		if(null != fees)
		{
			fees_id = fees.getId();
			ywFees.setId(fees.getId());
			ywFees.initUpdateData(userId, creatorName);
			ywFees.setCusId(business.getCustomerId());
			int updateCount = ywFeesMapper.updateByPrimaryKeySelective(ywFees);
			if(updateCount < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
			}
		}
		
		//业务信息表修改状态
		ywBusiness.initUpdateData(userId, creatorName);
		ywBusiness.setId(busiId);
		int updateCount = ywBusinessMapper.updateByPrimaryKeySelective(ywBusiness);
		if(updateCount == 0)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		} 
		else if(updateCount > 1)
		{
			throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
		}
		
		//查询按揭日报表字表
		WhereSqlExt whereSqlExt = new WhereSqlExt();
		String whereSql = "select t.id,t.item_code from yw_fees_sub t where t.busi_id = '"+busiId+"' and t.fees_id = '"+fees_id+"' and t.dp_status = 1 order by t.item_code asc";
		whereSqlExt.setWhereSql(whereSql);
		List<Map<String, String>> maps = publicDao.selectWhereSql(whereSqlExt);
		if(null != maps && 0 != maps.size())
		{
			String[] keys = key.split(",");
			String[] values = value.split(",");
			for(int i=0;i<maps.size();i++)
			{
				Map<String, String> mpaMap = maps.get(i);
				for(int j=0;j<keys.length;j++)
				{
					String item_code = mpaMap.get("item_code");
					if(item_code.equals(keys[j]))
					{
						YwFeesSub ywFeesSub = new YwFeesSub();
						ywFeesSub.setId(mpaMap.get("id"));
						ywFeesSub.setAmountItem(Double.valueOf(values[j]));
						ywFeesSub.initUpdateData(userId, creatorName);
						updateCount = ywFeesSubMapper.updateByPrimaryKeySelective(ywFeesSub);
						if(updateCount < 1)
						{
							throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
						}
						break;
					}
				}
			}
			return;
		}
		
		//增加按揭日报表字表信息
		if(null != key && !("").equals(key))
		{
			String[] keys = key.split(",");
			String[] values = value.split(",");
			
			if(null != keys && 0 != keys.length)
			{
				for(int i=0;i<keys.length;i++)
				{
					YwFeesSub ywFeesSub = new YwFeesSub();
					ywFeesSub.initInsertData(userId, creatorName);
					ywFeesSub.setBusiId(busiId);
					ywFeesSub.setCusId(business.getCustomerId());
					ywFeesSub.setFeesId(fees_id);
					ywFeesSub.setItemCode(keys[i]);
					ywFeesSub.setAmountItem(Double.valueOf(values[i]));
					int insertCount = ywFeesSubMapper.insert(ywFeesSub);
					if(insertCount < 1)
					{
						throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
					}
				}
			}
		}
		
		
//		//查询业务信息表数据
//		business = ywBusinessMapper.selectByPrimaryKey(busiId);
//		
//		//如果额外状态为已经登记  则不做任何操作
//		if(null != business.getAddedStatus1() && !("").equals(business.getAddedStatus1()))
//		{
//			int addedStatus1 = business.getAddedStatus1();
//			if(addedStatus1 == 10)
//			{
//				return;
//			}
//			
//			//如果是已经登记的话
//			if(addedStatus1 == 20)
//			{
//				FkAuditList fkAuditList = new FkAuditList();
//				fkAuditList.setBusiId(busiId);
//				fkAuditList.setModeId("M_fkjlsh");
//				fkAuditList.setStatusList(1);
//				fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
//				
//				if(null != fkAuditList && !("").equals(fkAuditList))
//				{
//					return;
//				}
//				
//				//如果电审二审状态40  and 资审二审状态85  则插入90状态  风控经理
//				if((null != business.getPhoneStatus() && !("").equals(business.getPhoneStatus())) && (null != business.getBusiStatus() && !("").equals(business.getBusiStatus())))
//				{
//					int phoneStatus = business.getPhoneStatus();
//					int busiStatus = business.getBusiStatus();
//					
//					if(phoneStatus == 40 && busiStatus == 85)
//					{
//						//查询当前业务编号的待审核数据
//						fkAuditList = new FkAuditList();
//						fkAuditList.setBusiId(busiId);
//						fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
//						
//						if(null == fkAuditList || ("").equals(fkAuditList))
//						{
//							return;
//						}
//						
//						fkAuditList.initInsertData(userId, creatorName);
//						fkAuditList.setModeId("M_fkjlsh");
//						fkAuditList.setStatusList(1);
//						fkAuditList.setOperatorId("");
//						fkAuditList.setOperatorName("");
//						int insertCount = fkAuditListMapper.insert(fkAuditList);
//						if(insertCount < 1)
//						{
//							throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
//						} 
//						
//						//改状态为90
//						YwBusiness b = new YwBusiness();
//						b.setId(busiId);
//						b.setBusiStatus(90);
//						updateCount = ywBusinessMapper.updateByPrimaryKeySelective(b);
//						if(updateCount == 0)
//						{
//							throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
//						} 
//						else if(updateCount > 1)
//						{
//							throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
//						}
//					}
//				}
//			}
//		}
	}

	/* 
	* @author zhangpp
	* <p>Title: saveKeHuDengJiService</p> 
	* <p>Description: </p> 
	* @param paramsExt
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#saveKeHuDengJiService(com.zjdiepu.www.model.zpp.pub.ext.ParamsExt, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void saveKeHuDengJiService(ParamsExt paramsExt,AbstractSysUser currentUser,YwBusinessCar ywBusinessCar) 
	{
		
		
		String userId = currentUser.getId();
		String creatorName = currentUser.getName();
		
		String busiId = paramsExt.getBusiId();
		
		//查询车辆信息
		if(null != ywBusinessCar && !("").equals(ywBusinessCar))
		{
			YwBusinessCar car = new YwBusinessCar();
			car.setBusiId(busiId);
			car.setDpStatus(1);
			car = ywBusinessCarMapper.selectRefined(car);
			if(null == car || ("").equals(car))
			{
				ywBusinessCar.initInsertData(userId, creatorName);
				int count = ywBusinessCarMapper.insert(ywBusinessCar);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessCarMapper error");
				} 
			}
			else
			{
				ywBusinessCar.setId(car.getId());
				int count = ywBusinessCarMapper.updateByPrimaryKeySelective(ywBusinessCar);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),""
							+ " error");
				} 
			}
			
			
			//贷款信息表
			YwBusinessLoan ywBusinessLoan = new YwBusinessLoan();
			ywBusinessLoan.setBusiId(busiId);
			ywBusinessLoan.setDpStatus(1);
			ywBusinessLoan = ywBusinessLoanMapper.selectRefined(ywBusinessLoan);
			if(null == ywBusinessLoan)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessLoanMapper is null");
			}
			
			//修改价格
			ywBusinessLoan.setCarPrice(ywBusinessCar.getPrice());
			int count = ywBusinessLoanMapper.updateByPrimaryKeySelective(ywBusinessLoan);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessLoanMapper error");
			}
		}
		
		
		
		
		//查询待审批列表
		FkAuditListVo auditListVo = daiZhongYwService.getYwBusinessSaveFkAuditList(paramsExt);
		
		if(null == auditListVo || ("").equals(auditListVo))
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		}
		
		YwTransfer ywTransfer = new YwTransfer();
		ywTransfer.setDpStatus(1);
		ywTransfer.setBusiId(paramsExt.getBusiId());
		ywTransfer = isYwTransferMapper.selectRefined(ywTransfer);
		if(null != ywTransfer && !("").equals(ywTransfer))
		{
			//过户的时间  此方法只为解决移动的兼容性问题
			Date dateTransfer = paramsExt.getDateTransfer();
			ywTransfer.setStatusTransfer(10);
			if(null == dateTransfer || ("").equals(dateTransfer))
			{
				Date submitTimeStart = ZhppDateUtil.convertDate(paramsExt.getSubmitTimeStart(),"yyyy-MM-dd");
				ywTransfer.setDateTransfer(submitTimeStart);
			}
			else
			{
				ywTransfer.setDateTransfer(paramsExt.getDateTransfer());
			}
			ywTransfer.setRemarks(paramsExt.getRemark());
			int updateCount = isYwTransferMapper.updateByPrimaryKeySelective(ywTransfer);
			if(updateCount == 0)
			{
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
			} 
			else if(updateCount > 1)
			{
				throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
			}
			
			FkAuditList fkAuditList = new FkAuditList();
			fkAuditList.setBusiId(paramsExt.getBusiId());
			fkAuditList.setModeId("M_ghsh");
			fkAuditList.setStatusList(1);
			fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
			
			if(null == fkAuditList || ("").equals(fkAuditList))
			{
				//待审核表数据添加
				fkAuditList = new FkAuditList();
				fkAuditList.initInsertData(userId, creatorName);
				fkAuditList.setBusiId(auditListVo.getBusi_id());
				fkAuditList.setModeId("M_ghsh");
				fkAuditList.setSource("过户资料登记");
				fkAuditList.setLoanAmount(auditListVo.getLoan_amount());
				fkAuditList.setBusiConfirmTime(auditListVo.getBusi_confirm_time());
				fkAuditList.setChannelStatus(Integer.valueOf(auditListVo.getChannel_status()));
				fkAuditList.setChannelStatusName(auditListVo.getChannel_status_name());
				fkAuditList.setChannelType(auditListVo.getChannel_type());
				fkAuditList.setChannelTypeName(auditListVo.getChannel_type_name());
				fkAuditList.setDealer(auditListVo.getDealer());
				fkAuditList.setDepartmentName(auditListVo.getDepartment_name());
				fkAuditList.setCusName(auditListVo.getCus_name());
				fkAuditList.setCusIdno(auditListVo.getCus_idno());
				fkAuditList.setBankname(auditListVo.getBankname());
				fkAuditList.setAcceptDate(auditListVo.getAccept_date());
				fkAuditList.setAssigningTaskType(auditListVo.getAssigning_task_type());
				fkAuditList.setStatusList(1);
				fkAuditList.setSalersmanName(auditListVo.getSalersman_name());
			
				//添加待审批列表
				int insertCount = fkAuditListMapper.insert(fkAuditList);
				if(insertCount < 1)
				{
					throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
				} 
			}
			return;
		}
		
		
		//待审核表数据添加
		FkAuditList fkAuditList = new FkAuditList();
		fkAuditList.initInsertData(userId, creatorName);
		fkAuditList.setBusiId(auditListVo.getBusi_id());
		fkAuditList.setModeId("M_ghsh");
		fkAuditList.setSource("过户资料登记");
		fkAuditList.setLoanAmount(auditListVo.getLoan_amount());
		fkAuditList.setBusiConfirmTime(auditListVo.getBusi_confirm_time());
		fkAuditList.setChannelStatus(Integer.valueOf(auditListVo.getChannel_status()));
		fkAuditList.setChannelStatusName(auditListVo.getChannel_status_name());
		fkAuditList.setChannelType(auditListVo.getChannel_type());
		fkAuditList.setChannelTypeName(auditListVo.getChannel_type_name());
		fkAuditList.setDealer(auditListVo.getDealer());
		fkAuditList.setDepartmentName(auditListVo.getDepartment_name());
		fkAuditList.setCusName(auditListVo.getCus_name());
		fkAuditList.setCusIdno(auditListVo.getCus_idno());
		fkAuditList.setBankname(auditListVo.getBankname());
		fkAuditList.setAcceptDate(auditListVo.getAccept_date());
		fkAuditList.setAssigningTaskType(auditListVo.getAssigning_task_type());
		fkAuditList.setStatusList(1);
		fkAuditList.setSalersmanName(auditListVo.getSalersman_name());
	
		//添加待审批列表
		int insertCount = fkAuditListMapper.insert(fkAuditList);
		if(insertCount < 1)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		} 
		
		//插入 yw_transfer 表数据
		//过户的时间  此方法只为解决移动的兼容性问题
		ywTransfer = new YwTransfer();
		Date dateTransfer = paramsExt.getDateTransfer();
		if(null == dateTransfer || ("").equals(dateTransfer))
		{
			Date submitTimeStart = ZhppDateUtil.convertDate(paramsExt.getSubmitTimeStart(),"yyyy-MM-dd");
			ywTransfer.setDateTransfer(submitTimeStart);
		}
		else
		{
			ywTransfer.setDateTransfer(paramsExt.getDateTransfer());
		}
		ywTransfer.initInsertData(currentUser.getId(), currentUser.getName());
		ywTransfer.setBusiId(paramsExt.getBusiId());
		ywTransfer.setCusId(currentUser.getId());
		ywTransfer.setStatusTransfer(10);
		ywTransfer.setRemarks(paramsExt.getRemark());
		insertCount = isYwTransferMapper.insert(ywTransfer);
		if(insertCount < 1)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		} 
	}

	/* 
	* @author zhangpp
	* <p>Title: saveYwShouLiQingDaiBiao</p> 
	* <p>Description: </p> 
	* @param ywLoanAbandon
	* @param ywBusiness
	* @param currentUser 
	* @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#saveYwShouLiQingDaiBiao(com.zjdiepu.www.model.yw.dto.YwLoanAbandon, com.zjdiepu.www.model.yw.dto.YwBusiness, com.zjdiepu.www.base.core.AbstractSysUser) 
	* @version V1.0
	*/
	@Override
	public void saveYwShouLiQingDaiBiao(YwLoanAbandon ywLoanAbandon,
			YwBusiness ywBusiness, AbstractSysUser currentUser) {
		
		
		String userId = currentUser.getId();
		String creatorName = currentUser.getName();
		
		//查询是否有值
		YwLoanAbandon yAbandon = new YwLoanAbandon();
		yAbandon.setBusiId(ywLoanAbandon.getBusiId());
		yAbandon = ywLoanAbandonMapper.selectRefined(yAbandon);
		if(null == yAbandon || ("").equals(yAbandon))
		{
			//插入   yw_loan_abandon  表
			ywLoanAbandon.initInsertData(userId, creatorName);
			ywLoanAbandonMapper.insert(ywLoanAbandon);
		}
		else
		{
			//修改   yw_loan_abandon  表
			ywLoanAbandon.initUpdateData(userId, creatorName);
			ywLoanAbandon.setId(yAbandon.getId());
			int updateCount = ywLoanAbandonMapper.updateByPrimaryKeySelective(ywLoanAbandon);
			if(updateCount == 0)
			{
				throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
			} 
			else if(updateCount > 1)
			{
				throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
			}
		}
		
		//修改业务信息表的状态  9810
		ywBusiness.initUpdateData(userId, creatorName);
		int updateCount = ywBusinessMapper.updateByPrimaryKeySelective(ywBusiness);
		if(updateCount == 0)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		} 
		else if(updateCount > 1)
		{
			throw new BaseException(ResultFlagType.MULTI_DATA.getCode().toString(),ResultFlagType.MULTI_DATA.getValue());
		}
		
		
		//业务主键
		String busiId = ywLoanAbandon.getBusiId();
		
		FkAuditList fkAuditList = new FkAuditList();
		fkAuditList.setBusiId(busiId);
		fkAuditList.setStatusList(1);
		fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
		
		if(null == fkAuditList || ("").equals(fkAuditList))
		{
			return;
		}
		
		WhereSqlExt whereSqlExt = new WhereSqlExt();
		String whereSql = "update fk_audit_list t set t.status_list = '4' where busi_id = '"+busiId+"'";
		whereSqlExt.setWhereSql(whereSql);
		updateCount = publicDao.updateWhereSql(whereSqlExt);
		if(updateCount < 1)
		{
			throw new BaseException(ResultFlagType.MISSING.getCode().toString(),ResultFlagType.MISSING.getValue());
		} 
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  diepuDealer</p>  
	*  <p>Description:  </p>  
	*  @param currentUser
	*  @param dpBaseDealerInfo
	*  @param dpBaseDealerInfoSub  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#diepuDealer(com.zjdiepu.www.base.core.AbstractSysUser, com.zjdiepu.www.model.base.dto.DpBaseDealerInfo, com.zjdiepu.www.model.base.dto.DpBaseDealerInfoSub)  
	*  @version  V1.0
	*/
	@Override
	public void diepuDealer(AbstractSysUser currentUser,
			DpBaseDealerInfo dpBaseDealerInfo,
			DpBaseDealerInfoSub dpBaseDealerInfoSub) {
		
		
		
		String userId = currentUser.getId();
		String loginName = currentUser.getName();
		
		String dealerCode = "J" + new DecimalFormat("10000").format(serialNumberService.createSerialNumber(CodeType.DEALERINFO,null, false));
		dpBaseDealerInfo.initInsertData(userId, loginName);
		dpBaseDealerInfo.setDealerCode(dealerCode);
		int insertCount = dpBaseDealerInfoMapper.insert(dpBaseDealerInfo);
		if(insertCount < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		}
		
		dpBaseDealerInfoSub.initInsertData(userId, loginName);
		dpBaseDealerInfoSub.setDealerId(dpBaseDealerInfo.getId());
		insertCount = dpBaseDealerInfoSubMapper.insert(dpBaseDealerInfoSub);
		if(insertCount < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		}
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  getDealerSub</p>  
	*  <p>Description:  </p>  
	*  @param dealerId
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#getDealerSub(java.lang.String)  
	*  @version  V1.0
	*/
	@Override
	public DpBaseDealerInfoSub getDealerSub(String dealerId) {
		
		DpBaseDealerInfoSub dpBaseDealerInfoSub = new DpBaseDealerInfoSub();
		dpBaseDealerInfoSub.setDealerId(dealerId);
		dpBaseDealerInfoSub = dpBaseDealerInfoSubMapper.selectRefined(dpBaseDealerInfoSub);
		return dpBaseDealerInfoSub;
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  diepuDealerUpdate</p>  
	*  <p>Description:  </p>  
	*  @param currentUser
	*  @param dpBaseDealerInfo
	*  @param dpBaseDealerInfoSub  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#diepuDealerUpdate(com.zjdiepu.www.base.core.AbstractSysUser, com.zjdiepu.www.model.base.dto.DpBaseDealerInfo, com.zjdiepu.www.model.base.dto.DpBaseDealerInfoSub)  
	*  @version  V1.0
	*/
	@Override
	public void diepuDealerUpdate(AbstractSysUser currentUser,
			DpBaseDealerInfo dpBaseDealerInfo,
			DpBaseDealerInfoSub dpBaseDealerInfoSub) {
		
		
		String userId = currentUser.getId();
		String loginName = currentUser.getName();
		
		dpBaseDealerInfo.initUpdateData(userId, loginName);
		dpBaseDealerInfo.setId(dpBaseDealerInfoSub.getDealerId());
		int updateCount = dpBaseDealerInfoMapper.updateByPrimaryKeySelective(dpBaseDealerInfo);
		if(updateCount < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		}
		
		DpBaseDealerInfoSub baseDealerInfoSub = new DpBaseDealerInfoSub();
		baseDealerInfoSub.setDealerId(dpBaseDealerInfoSub.getDealerId());
		baseDealerInfoSub = dpBaseDealerInfoSubMapper.selectRefined(baseDealerInfoSub);
		
		if(null == baseDealerInfoSub || ("").equals(baseDealerInfoSub))
		{
			return;
		}
		
		dpBaseDealerInfoSub.initUpdateData(userId, loginName);
		dpBaseDealerInfoSub.setId(baseDealerInfoSub.getId());
		updateCount = dpBaseDealerInfoSubMapper.updateByPrimaryKeySelective(dpBaseDealerInfoSub);
		if(updateCount < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		}
	}

	/*  
	*  @author  zhangpp
	*  <p>Title:  bankFileUpload</p>  
	*  <p>Description:  </p>  
	*  @param currentUser
	*  @param path  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#bankFileUpload(com.zjdiepu.www.base.core.AbstractSysUser, java.lang.String)  
	*  @version  V1.0
	*/
	/**  
	*  @author  zhangpp
	*  @Title:  bankFileUpload  
	*    
	*  @param  @param currentUser
	*  @param  @param path
	*  @param  @throws Exception        设定文件  
	*  @return  void        返回类型  
	*  @version  V1.0
	*  @throws  
	*/
	@Override
	public void diepuBankFileUpload(AbstractSysUser currentUser, String path) throws Exception {
		
		
		String userId = currentUser.getId();
		String name = currentUser.getName();
		
		InputStream is = new FileInputStream(path);
		XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
		List<DzLoanMiddleBankImport> dzLoanMiddleBankImports = new ArrayList<DzLoanMiddleBankImport>();
		for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) 
		{
			XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
            if (null == xssfSheet || 0 == xssfSheet.getLastRowNum()) 
            {
                continue;
            }
            
            //判断是否符合本次导入的模板
            XSSFRow xssfRow = xssfSheet.getRow(0);
            XSSFCell cellName1 = xssfRow.getCell(0);
            String cell =getValue(cellName1).trim();
            if(!cell.equals("上午下午"))
            {
            	throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
            }
            
            // 获取当前工作薄的每一行
            for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) 
            {
            	xssfRow = xssfSheet.getRow(rowNum);
            	if (null != xssfRow && !("").equals(xssfRow)) 
            	{
            		XSSFCell time_receive_bank2 = xssfRow.getCell(0);
            		
            		if(null != time_receive_bank2 && !("").equals(time_receive_bank2))
            		{
            			DzLoanMiddleBankImport middleBankImport = new DzLoanMiddleBankImport();
            			middleBankImport.initInsertData(userId, name);
            			String timeReceiveBank = getValue(xssfRow.getCell(1));
            			timeReceiveBank = timeReceiveBank.replace(".", "-");
            			middleBankImport.setTimeReceiveBank(ZhppDateUtil.convertDate(timeReceiveBank, ZhppDateUtil.SHORT_DATE_FORMAT));
            			middleBankImport.setTimeReceiveBank2(getValue(time_receive_bank2));
            			middleBankImport.setCustomerName(getValue(xssfRow.getCell(2)));
            			middleBankImport.setCustomerNo(getValue(xssfRow.getCell(3)));
            			middleBankImport.setCarType(getValue(xssfRow.getCell(4)));
            			double loanMonth = 0;
            			if(null != getValue(xssfRow.getCell(5)) && !getValue(xssfRow.getCell(5)).equals(""))
            			{
            				loanMonth = Double.valueOf(getValue(xssfRow.getCell(5)));
            			}
            			
            			int loan = (int) loanMonth;
            			middleBankImport.setLoanMonth(loan);
            			middleBankImport.setLoanAmount(Double.valueOf(getValue(xssfRow.getCell(6))));
            			middleBankImport.setSalesmanCode(getValue(xssfRow.getCell(7)));
            			
            			String timeRemit = getValue(xssfRow.getCell(8));
            			timeRemit = timeRemit.replace(".", "-");
            			middleBankImport.setTimeRemit(ZhppDateUtil.convertDate(timeRemit, ZhppDateUtil.SHORT_DATE_FORMAT));
            			if(null != getValue(xssfRow.getCell(9)) && getValue(xssfRow.getCell(9)).equals("未放款"))
            			{
            				middleBankImport.setStatusNameRemit(0);
            			}
            			else
            			{
            				middleBankImport.setStatusNameRemit(1);
            			}
            			String timeReceiveOpencard = getValue(xssfRow.getCell(11));
            			timeReceiveOpencard = timeReceiveOpencard.replace(".", "-");
            			middleBankImport.setTimeReceiveOpencard(ZhppDateUtil.convertDate(timeReceiveOpencard, ZhppDateUtil.SHORT_DATE_FORMAT));
            			middleBankImport.setCardnoRefund(getValue(xssfRow.getCell(12)));
            			middleBankImport.setContractNo(getValue(xssfRow.getCell(13)));
            			
            			String timeSubsequentReceive = getValue(xssfRow.getCell(16));
            			timeSubsequentReceive = timeSubsequentReceive.replace(".", "-");
            			middleBankImport.setTimeSubsequentReceive(ZhppDateUtil.convertDate(timeSubsequentReceive, ZhppDateUtil.SHORT_DATE_FORMAT));
            			middleBankImport.setRemarkSubsequent(getValue(xssfRow.getCell(14)));
            			middleBankImport.setPeopleLoan(getValue(xssfRow.getCell(17)));
            			middleBankImport.setTxtPledge(getValue(xssfRow.getCell(10)));
            			
            			String timeSubsequentInform = getValue(xssfRow.getCell(15));
            			timeSubsequentInform = timeSubsequentInform.replace(".", "-");
            			middleBankImport.setTimeSubsequentInform(ZhppDateUtil.convertDate(timeSubsequentInform, ZhppDateUtil.SHORT_DATE_FORMAT));
            			dzLoanMiddleBankImports.add(middleBankImport);
            			middleBankImport = null;
            		}
            	}
            }
		}
		int count = dzLoanMiddleBankImportMapper.insertBatch(dzLoanMiddleBankImports);
		if(count < 1)
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),ResultFlagType.FAIL.getValue());
		}
	}
	
	
    //转换数据格式
   @SuppressWarnings("static-access")
   private String getValue(XSSFCell xssfRow) 
   {
	   if(null == xssfRow || ("").equals(xssfRow))
	   {
		   return "";
	   }
       if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
           return String.valueOf(xssfRow.getBooleanCellValue());
       } else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) {
           return String.valueOf(xssfRow.getNumericCellValue());
       } else {
           return String.valueOf(xssfRow.getStringCellValue());
       }
   }

	/*  
	*  @author  zhangpp
	*  <p>Title:  getDaKuanKeHuTableList</p>  
	*  <p>Description:  </p>  
	*  @param daKuanKeHuTableExe
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#getDaKuanKeHuTableList(com.zjdiepu.www.model.zpp.ywsl.ext.DaKuanKeHuTableExe)  
	*  @version  V1.0
	*/
	@Override
	public List<DaKuanKeHuTable> getDaKuanKeHuTableList(
			DaKuanKeHuTableExe daKuanKeHuTableExe) {
		
		return YwShouLiDao.getDaKuanKeHuTableList(daKuanKeHuTableExe);
	}
	
	/*  
	*  @author  zhangpp
	*  <p>Title:  countDaKuanKeHuTable</p>  
	*  <p>Description:  </p>  
	*  @param daKuanKeHuTableExe
	*  @return  
	*  @see com.zjdiepu.www.ibiz.zpp.YwShouLiService#countDaKuanKeHuTable(com.zjdiepu.www.model.zpp.ywsl.ext.DaKuanKeHuTableExe)  
	*  @version  V1.0
	*/
	@Override
	public int countDaKuanKeHuTable(DaKuanKeHuTableExe daKuanKeHuTableExe) {
		
		return YwShouLiDao.countDaKuanKeHuTable(daKuanKeHuTableExe);
	}

	
	@Override
	public void diepuCarTransfer(AbstractSysUser currentUser,YwTransfer ywTransfer, YwBusinessCar ywBusinessCar,String executeType) 
	{
		
		String userId = currentUser.getId();
		String loginName = currentUser.getName();
		
		String busiId = ywTransfer.getBusiId();
		if(StringUtils.isBlank(busiId) || StringUtils.isBlank(executeType))
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		YwTransfer transfer = new  YwTransfer();
		transfer.setBusiId(busiId);
		transfer.setDpStatus(1);
		transfer = ywTransferMapper.selectRefined(transfer);
		
		if(executeType.equals("1"))
		{
			if(null == transfer)
			{
				ywTransfer.initInsertData(userId, loginName);
				ywTransfer.setStatusTransfer(1);
				int count = ywTransferMapper.insert(ywTransfer);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"ywTransferMapper save error");
				}
				return;
			}
			
			if(null != transfer.getStatusTransfer())
			{
				if(transfer.getStatusTransfer() == 10)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"已经提交过了，不能再执行保存");
				}
			}
			
			ywTransfer.setId(transfer.getId());
			ywTransfer.initUpdateData(userId, loginName);
			int count = ywTransferMapper.updateByPrimaryKeySelective(ywTransfer);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"ywTransferMapper update error");
			}
			return;
		}
		
		//提交
		if(executeType.equals("2"))
		{
			if(null == transfer)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"请先保存，在提交");
			}
			
			if(null != transfer.getStatusTransfer())
			{
				if(transfer.getStatusTransfer() == 10)
				{
					FkAuditList fkAuditList = new FkAuditList();
					fkAuditList.setBusiId(busiId);
					fkAuditList.setModeId(ModeIDType.GHSH.getCode());
					fkAuditList.setStatusList(1);
					fkAuditList.setDpStatus(1);
					fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
					if(null != fkAuditList)
					{
						throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"已经提交过了");
					}
				}
			}
			
			ywTransfer.setId(transfer.getId());
			ywTransfer.setStatusTransfer(10);
			int count = ywTransferMapper.updateByPrimaryKeySelective(ywTransfer);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"ywTransferMapper update error");
			}
			
			//贷款信息表
			YwBusinessLoan ywBusinessLoan = new YwBusinessLoan();
			ywBusinessLoan.setBusiId(busiId);
			ywBusinessLoan.setDpStatus(1);
			ywBusinessLoan = ywBusinessLoanMapper.selectRefined(ywBusinessLoan);
			if(null == ywBusinessLoan)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessLoanMapper is null");
			}
			
			//修改价格
			ywBusinessLoan.setCarPrice(ywBusinessCar.getPrice());
			ywBusinessLoan.initUpdateData(userId, loginName);
			count = ywBusinessLoanMapper.updateByPrimaryKeySelective(ywBusinessLoan);
			if(count < 1)
			{
				throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"ywBusinessLoanMapper update error");
			}
			
			//过户审核处理
			FkAuditList fkAuditList = new FkAuditList();
			fkAuditList.setBusiId(busiId);
			fkAuditList.setModeId(ModeIDType.GHSH.getCode());
			fkAuditList.setStatusList(1);
			fkAuditList.setDpStatus(1);
			fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
			if(null == fkAuditList)
			{
				fkAuditList = new FkAuditList();
				fkAuditList.setBusiId(busiId);
				fkAuditList.setDpStatus(1);
				fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
				if(null == fkAuditList)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"fkAuditListMapper is null");
				}
				
				fkAuditList.initInsertData(userId, loginName);
				fkAuditList.setModeId(ModeIDType.GHSH.getCode());
				fkAuditList.setStatusList(1);
				fkAuditList.setSource("二手车过户");
				fkAuditList.setRemarks("二手车过户");
				fkAuditList.setOperatorId("");
				fkAuditList.setOperatorName("");
				fkAuditList.setAcceptDate(null);
				count = fkAuditListMapper.insert(fkAuditList);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"fkAuditListMapper insert error");
				}
			}
			return;
		}
		
		//手机端的处理
		if(executeType.equals("3"))
		{
			if(null != transfer)
			{
				if(null != transfer.getStatusTransfer())
				{
					if(transfer.getStatusTransfer() == 10)
					{
						throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"已经提交过了");
					}
				}
			}
			
			if(null == transfer)
			{
				ywTransfer.initInsertData(userId, loginName);
				ywTransfer.setStatusTransfer(10);
				int count = ywTransferMapper.insert(ywTransfer);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"ywTransferMapper insert error");
				}
			}
			
			if(null != transfer)
			{
				ywTransfer.setId(transfer.getId());
				int count = ywTransferMapper.updateByPrimaryKeySelective(ywTransfer);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"ywTransferMapper updateByPrimaryKeySelective error");
				}
			}
			
			FkAuditList fkAuditList = new FkAuditList();
			fkAuditList.setBusiId(busiId);
			fkAuditList.setModeId(ModeIDType.GHSH.getCode());
			fkAuditList.setStatusList(1);
			fkAuditList.setDpStatus(1);
			fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
			if(null == fkAuditList)
			{
				fkAuditList = new FkAuditList();
				fkAuditList.setBusiId(busiId);
				fkAuditList.setDpStatus(1);
				fkAuditList = fkAuditListMapper.selectRefined(fkAuditList);
				if(null == fkAuditList)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"fkAuditListMapper selectRefined null");
				}
				fkAuditList.initInsertData(userId, loginName);
				fkAuditList.setModeId(ModeIDType.GHSH.getCode());
				fkAuditList.setStatusList(1);
				fkAuditList.setSource("二手车过户");
				fkAuditList.setRemarks("手机端二手车过户");
				fkAuditList.setOperatorId("");
				fkAuditList.setOperatorName("");
				fkAuditList.setAcceptDate(null);
				int count = fkAuditListMapper.insert(fkAuditList);
				if(count < 1)
				{
					throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"fkAuditListMapper insert error");
				}
			}
		}
	}
}
